window.onload = function() {

        var game = new Phaser.Game(960, 540, Phaser.AUTO, '', { preload: preload, create: create });
        var name;
        var count;

        function preload () {

            game.load.image('coin', 'graphic/coin.png');
            game.load.image('door', 'graphic/door.png');
            game.load.image('door_', 'graphic/door_.png');

        }

        function create () {

            var coin = game.add.sprite(600, game.world.centerY, 'coin');
            coin.anchor.setTo(0.5, 0.5);
            
            var door = game.add.sprite(870, game.world.centerY, 'door');
            door.anchor.setTo(0.5, 0.5);
            
            door.inputEnabled = true;
            
            door.events.onInputOver.add(over, this);
            door.events.onInputOut.add(out, this);
            door.events.onInputDown.add(click, this);
            
            name = game.add.text(150, 16, getDb('php/name.php'), { fill: '#ffffff' });
            
            button = game.add.button(150, 150, 'button', actionOnClick, this, 2, 1, 0);
            count = game.add.text(150, 70, getDb('php/getCount.php'), { fill: '#ffffff' });
        }
    
        function actionOnClick() {
            setDb('php/setCount.php?count=' + count.text + '&uname=' + name.text);
            count.setText(getDb('php/getCount.php'));
        }
        
        function over(door) {
            door.loadTexture('door_', 0);
        }
        
        function out(door) {
            door.loadTexture('door', 0);
        }
        
        function click() {
            alert('you clicked');
        }
    
        function getDb(file) {
            var data;
            var oReq = new XMLHttpRequest(); //New request object
            oReq.onload = function() {
                data = this.responseText;
            };
            oReq.open('get', file, false);

            oReq.send();
            
            return data;
        }
    
        function setDb(file) {
            var data;
            var oReq = new XMLHttpRequest(); //New request object
            oReq.onload = function() {
                
            };
            oReq.open('get', file, false);

            oReq.send();
        }

    };